import Vuex from "vuex"
import Vue from "vue"
import { ADD, ASYNCADD, SUB } from "./mutations-types"
Vue.use(Vuex);
let store = new Vuex.Store({
    state: {
        counter: 11
    },
    mutations: {
        [ADD]: function(state, step) {
            state.counter += step;
        },
        [SUB]: function(state, payload) {
            console.log(payload);
            state.counter -= payload.data.step;
        }
    },
    actions: {
        [ASYNCADD]: function(store, step) {
            setTimeout(function() {
                store.commit(ADD, step);
            }, 2000)
        }
    },
    getters: {
        isEvenOrOdd: function(state) {
            // return "1234567"
            return state.counter % 2 === 0 ? "偶数" : "奇数";
        }
    }
});
export default store;